package testes.vSys.util;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

public class ValidationErrorsTag extends TagSupport{

	private static final long serialVersionUID = 6488536683173003242L;

	public static final String VALIDATION_ERRORS = "validationErrorsCollection";

	@Override
	public int doStartTag() throws JspException {
		Object ve = pageContext.getSession().getAttribute(VALIDATION_ERRORS);
		pageContext.getSession().removeAttribute(VALIDATION_ERRORS);
		
		System.out.println("entrou na tag -> "+ve);

		if (ve != null){
			Collection errors = (Collection)ve; 
				JspWriter out = pageContext.getOut();

				try {

					Iterator iErrors = errors.iterator();
					while (iErrors.hasNext()){
						out.println((String)iErrors.next() + " <br/>");
					}

				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}	
		}

		return super.doStartTag();
	}

}
